<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><script type="text/javascript" src="https://cdn.jsdelivr.net/gh/opencobra/cobratoolbox@ffa0229fc0c01c9236bb7e961f65712443277719/latest/_static/js/iframeResizer.contentWindow.min.js"></script><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,IE=9,chrome=1"><meta name="generator" content="MATLAB 2021a"><title>Input and output of reconstructions and models </title><style type="text/css">.rtcContent { padding: 30px; } .S0 { margin: 3px 10px 5px 4px; padding: 0px; line-height: 28.8px; min-height: 0px; white-space: normal; color: rgb(213, 80, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 24px; font-weight: normal; text-align: left;  }
.S1 { margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: normal; color: rgb(60, 60, 60); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;  }
.S2 { margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: normal; text-align: left;  }
.S3 { margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px;  }
.S4 { margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: normal;  }
.S5 { margin: 3px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: normal; color: rgb(60, 60, 60); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;  }
.CodeBlock { background-color: #F7F7F7; margin: 10px 0 10px 0;}
.S6 { border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S7 { color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px;  }
/* Styling that is common to warnings and errors is in diagnosticOutput.css */.embeddedOutputsErrorElement {    min-height: 18px;    max-height: 250px;    overflow: auto;}
.embeddedOutputsErrorElement.inlineElement {}
.embeddedOutputsErrorElement.rightPaneElement {}
/* Styling that is common to warnings and errors is in diagnosticOutput.css */.embeddedOutputsWarningElement{    min-height: 18px;    max-height: 250px;    overflow: auto;}
.embeddedOutputsWarningElement.inlineElement {}
.embeddedOutputsWarningElement.rightPaneElement {}
/* Copyright 2015-2019 The MathWorks, Inc. *//* In this file, styles are not scoped to rtcContainer since they could be in the Dojo Tooltip */.diagnosticMessage-wrapper {    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;    font-size: 12px;}
.diagnosticMessage-wrapper.diagnosticMessage-warningType {    color: rgb(255,100,0);}
.diagnosticMessage-wrapper.diagnosticMessage-warningType a {    color: rgb(255,100,0);    text-decoration: underline;}
.diagnosticMessage-wrapper.diagnosticMessage-errorType {    color: rgb(230,0,0);}
.diagnosticMessage-wrapper.diagnosticMessage-errorType a {    color: rgb(230,0,0);    text-decoration: underline;}
.diagnosticMessage-wrapper .diagnosticMessage-messagePart,.diagnosticMessage-wrapper .diagnosticMessage-causePart {    white-space: normal;}
.diagnosticMessage-wrapper .diagnosticMessage-stackPart {    white-space: normal;}
.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {    white-space: normal;    word-wrap:  initial;    min-height: 18px;    max-height: 250px;    overflow: auto;}
.textElement,.rtcDataTipElement .textElement {    padding-top: 3px;}
.embeddedOutputsTextElement.inlineElement,.embeddedOutputsVariableStringElement.inlineElement {}
.inlineElement .textElement {}
.embeddedOutputsTextElement.rightPaneElement,.embeddedOutputsVariableStringElement.rightPaneElement {    min-height: 16px;}
.rightPaneElement .textElement {    padding-top: 2px;    padding-left: 9px;}
.S8 { margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: normal; text-align: left;  }
.S9 { border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 0px none rgb(0, 0, 0); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S10 { border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S11 { border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S12 { margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: normal; text-align: center;  }
.S13 { border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }</style></head><body><div class = rtcContent><h1  class = 'S0'><span>Input and output of reconstructions and models </span></h1><h2  class = 'S1'><span>Author(s): Thomas Pfau, LCSB, University of Luxembourg.</span></h2><h2  class = 'S1'><span>Reviewers: Catherine Clancy, LCSB, University of Luxembourg.</span></h2><h2  class = 'S1'><span>Francisco J. Planes, Department of Biomedical Engineering and Sciences, Tecnun, University of Navarra.</span></h2><h2  class = 'S1'><span>INTRODUCTION</span></h2><div  class = 'S2'><span>This tutorial aims at providing information on how to load models into The COBRA Toolbox and export them to other formats.</span></div><h2  class = 'S1'><span>Available input formats</span></h2><div  class = 'S2'><span>The COBRA Toolbox supports the use of models in multiple formats, including:</span></div><ul  class = 'S3'><li  class = 'S4'><span>MAT-file format </span></li><li  class = 'S4'><span>Systems Biology Markup Language (SBML) format </span></li><li  class = 'S4'><span>SimPheny format</span></li><li  class = 'S4'><span>Excel format</span></li></ul><div  class = 'S2'><span>The most commonly used model format is a MAT-file (</span><span style=' font-family: monospace;'>.mat</span><span> ) format where by a simple MATLAB </span><span style=' font-family: monospace;'>struct</span><span> contains one or more of the fields defined in The COBRA Toolbox </span><a href = "https://opencobra.github.io/cobratoolbox/docs/COBRAModelFields.html"><span>Documentation</span></a><span>. </span></div><h2  class = 'S1'><span>MAT-file format</span></h2><div  class = 'S2'><span>A model in a MAT-file format is required to follow the rules defined in The COBRA Toolbox </span><a href = "https://opencobra.github.io/cobratoolbox/docs/ExcelModelFileDefinition.html"><span>Documentation</span></a><span>. </span></div><h2  class = 'S1'><span>SBML format</span></h2><div  class = 'S2'><span>The COBRA Toolbox currently supports models formats of SBML Level 3 version 1 (as defined </span><a href = "http://sbml.org/Documents/Specifications"><span>here</span></a><span>) and has legacy support for older versions of SBML. It also supports the Level 3 Flux Balance Constraints (FBC) package (both in version 1 and version 2). </span></div><div  class = 'S2'><span>The COBRA Toolbox will use the provided SBML IDs as IDs for the respective elements of the model structure, and use the name fields as names. It is assumed (but not necessary), that metabolite IDs start with a "M_", reaction IDs start with a "R_" , gene IDs start with a "G_", and compartment IDs start with a "C_". This is due to the limitation on identifiers in SBML and those starting sequences will be removed if they are consistently present in the model. </span></div><div  class = 'S2'><span>Metabolite IDs of the MAT-file format use a metabolite identfier followed by a compartment identifier in square brackets (e.g. ala_L[c]). Since brackets are illegal characters for SBML IDs, The COBRA Toolbox assumes, for all non boundary species, that a compartment identifier preceded by an underscore (e.g. SBML ID: M_ala_L_c) is equivalent to the MAT-file compartment identifiers and converted to a model as such.</span></div><div  class = 'S2'><span>The COBRA Toolbox has a legacy support for the NOTE Fields defined in </span><a href = "http://www.nature.com/nprot/journal/v6/n9/abs/nprot.2011.308.html"><span>Schellenberger et al, Nature Protocols, 2011</span></a><span>, but it is suggested to instead use annotations whenever possible. In general, if a fbc-package field and a NOTES field is present, the fbc-package value will be used (e.g. CHARGE for metabolites, or GENE_ASSOCIATION for reactions). The same applies to annotations, i.e. if there is an annotation for an EC number, the Notes field EC Number will be ignored. However, the charge field in SBML Level 2 will be overwritten by the Notes field definitions.</span></div><h2  class = 'S1'><span style=' font-weight: bold;'>SimPheny format</span></h2><div  class = 'S2'><span>SimPheny models provided in 3 or 4 files (4 if GPR rules are provided). The model identifiers will be used as presented in the SimPheny files.</span></div><h2  class = 'S1'><span>Excel format</span></h2><div  class = 'S2'><span>A model in a excel file formats are accepted by The COBRA Toolbox if the file adheres to the specifications listed in The COBRA Toolbox </span><a href = "https://opencobra.github.io/cobratoolbox/docs/ExcelModelFileDefinition.html"><span>Documentation</span></a><span>. </span></div><h2  class = 'S1'><span>Available output formats</span></h2><div  class = 'S2'><span>The COBRA Toolbox also allows storage in multiple file types as detailed below.</span></div><h2  class = 'S1'><span>MAT-files formats</span></h2><div  class = 'S2'><span>The MAT-file (</span><span style=' font-family: monospace;'>.mat</span><span> ) format is most commonly used. The MAT-file format make up is a simple MATLAB </span><span style=' font-family: monospace;'>struct</span><span> containing one or more of the fields defined in The COBRA Toolbox </span><a href = "https://opencobra.github.io/cobratoolbox/docs/COBRAModelFields.html"><span>Documentation</span></a><span>. It has the advantage of lossless data storage even for model specific fields not supported by The COBRA Toolbox.</span></div><h2  class = 'S1'><span>SBML format </span></h2><div  class = 'S2'><span>SBML is a commonly used format to store biological models. The COBRA Toolbox allows the generation of models using SBML Level 3 Version 1 and uses the FBC-package extension to encode constraint based properties. This is the format that is recommended for publication, as it can be used by many different tools and allows the best use of the model.</span></div><h2  class = 'S1'><span>Excel format</span></h2><div  class = 'S2'><span>Historically, models were often exchanged using Excel files, and this is still in use today. Some users prefer to have an overview of a model using Excel. The COBRA Toolbox offers an Excel export of the format described in The COBRA Toolbox </span><a href = "https://opencobra.github.io/cobratoolbox/docs/ExcelModelFileDefinition.html"><span>Documentation</span></a><span>.</span></div><h2  class = 'S1'><span>Text Format</span></h2><div  class = 'S2'><span>Finally, The COBRA Toolbox offers a simple textual export, which is essentially a tab separated file containing the reactions with their reaction formulas along with the associated GPRs, but no further information. This format only uses the required fields and will ignore any optional fields.</span></div><h2  class = 'S5'><span>EQUIPMENT SETUP</span></h2><h2  class = 'S1'><span style=' font-weight: bold;'>Initialize the COBRA Toolbox.</span></h2><div  class = 'S2'><span>Initialize The Cobra Toolbox using the </span><span style=' font-family: monospace;'>initCobraToolbox</span><span> function.</span></div><div class="CodeBlock"><div class="inlineWrapper outputs"><div  class = 'S6'><span style="white-space: normal"><span >initCobraToolbox(false) </span><span style="color: rgb(2, 128, 9);">% false, as we don't want to update</span></span></div><div  class = 'S7'><div class="inlineElement eoOutputWrapper embeddedOutputsTextElement scrollableOutput" uid="C86BAA61" data-testid="output_0" data-width="428" data-height="801" data-hashorizontaloverflow="true" style="width: 458px; max-height: 261px; white-space: normal; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;"><div class="textElement" style="white-space: normal; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;">      _____   _____   _____   _____     _____     |
     /  ___| /  _  \ |  _  \ |  _  \   / ___ \    |   COnstraint-Based Reconstruction and Analysis
     | |     | | | | | |_| | | |_| |  | |___| |   |   The COBRA Toolbox - 2018
     | |     | | | | |  _  { |  _  /  |  ___  |   |
     | |___  | |_| | | |_| | | | \ \  | |   | |   |   Documentation:
     \_____| \_____/ |_____/ |_|  \_\ |_|   |_|   |   <a href="http://opencobra.github.io/cobratoolbox" style="white-space: normal; font-style: normal; color: rgb(0, 95, 206); font-size: 12px;">http://opencobra.github.io/cobratoolbox</a>
                                                  | 

 &gt; Checking if git is installed ...  Done (version: 2.18.0).
 &gt; Checking if the repository is tracked using git ...  Done.
 &gt; Checking if curl is installed ...  Done.
 &gt; Checking if remote can be reached ...  Done.
 &gt; Initializing and updating submodules (this may take a while)... Done.
 &gt; Adding all the files of The COBRA Toolbox ...  Done.
 &gt; Define CB map output... set to svg.
 &gt; TranslateSBML is installed and working properly.
 &gt; Configuring solver environment variables ...
   - [---*] ILOG_CPLEX_PATH: /Applications/CPLEX_Studio128/cplex/matlab/x86-64_osx
   - [*---] GUROBI_PATH: /Library/gurobi752/mac64/matlab
   - [----] TOMLAB_PATH: --&gt; set this path manually after installing the solver ( see <a href="https://opencobra.github.io/cobratoolbox/docs/solvers.html" style="white-space: normal; font-style: normal; color: rgb(0, 95, 206); font-size: 12px;">instructions</a> )
   - [---*] MOSEK_PATH: /Applications/Mosek/8/
   Done.
 &gt; Checking available solvers and solver interfaces ... Done.
 &gt; Setting default solvers ... Done.
 &gt; Saving the MATLAB path ... Done.
   - The MATLAB path was saved in the default location.

 &gt; Summary of available solvers and solver interfaces

			Support 	   LP 	 MILP 	   QP 	 MIQP 	  NLP
	----------------------------------------------------------------------
	gurobi       	active        	    1 	    1 	    1 	    1 	    -
	ibm_cplex    	active        	    1 	    1 	    1 	    - 	    -
	tomlab_cplex 	active        	    0 	    0 	    0 	    0 	    -
	glpk         	active        	    1 	    1 	    - 	    - 	    -
	mosek        	active        	    1 	    - 	    1 	    - 	    -
	matlab       	active        	    1 	    - 	    - 	    - 	    1
	cplex_direct 	active        	    0 	    0 	    0 	    0 	    -
	dqqMinos     	active        	    1 	    - 	    - 	    - 	    -
	pdco         	active        	    1 	    - 	    1 	    - 	    -
	quadMinos    	active        	    1 	    - 	    - 	    - 	    -
	qpng         	passive       	    - 	    - 	    1 	    - 	    -
	tomlab_snopt 	passive       	    - 	    - 	    - 	    - 	    0
	lp_solve     	legacy        	    1 	    - 	    - 	    - 	    -
	----------------------------------------------------------------------
	Total        	-             	    9 	    3 	    5 	    1 	    1

 + Legend: - = not applicable, 0 = solver not compatible or not installed, 1 = solver installed.


 &gt; You can solve LP problems using: 'gurobi' - 'ibm_cplex' - 'glpk' - 'mosek' - 'matlab' - 'dqqMinos' - 'pdco' - 'quadMinos' - 'lp_solve' 
 &gt; You can solve MILP problems using: 'gurobi' - 'ibm_cplex' - 'glpk' 
 &gt; You can solve QP problems using: 'gurobi' - 'ibm_cplex' - 'mosek' - 'pdco' - 'qpng' 
 &gt; You can solve MIQP problems using: 'gurobi' 
 &gt; You can solve NLP problems using: 'matlab' 

&gt; Checking for available updates ... skipped</div></div></div></div></div><div  class = 'S8'><span>For this tutorial we will use a MAT-file formated model of the </span><span style=' font-style: italic;'>E.coli core</span><span> model [1]. First we will load the model into the tutorial directory (cleaning any old copies).</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span >cd(fileparts(which(</span><span style="color: rgb(170, 4, 249);">'tutorial_IO.mlx'</span><span >)));</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span style="color: rgb(2, 128, 9);">% Copy the file required for this tutorial (if they are not yet present).</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">try</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    delete </span><span style="color: rgb(170, 4, 249);">'ecoli_core_model.mat'</span><span >;</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    copyfile(which(</span><span style="color: rgb(170, 4, 249);">'ecoli_core_model.mat'</span><span >), </span><span style="color: rgb(170, 4, 249);">'.'</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><h2  class = 'S5'><span>PROCEDURE</span></h2><div  class = 'S2'><span>The time that it takes to load a model depends on the file format, the complexity of a model and the machine. The loading of a MAT-file, even of some large models, can take only seconds, whereas large SBML files can take a few minutes to load. </span></div><h2  class = 'S1'><span>Reading a model (timing: 1 second to a few minutes)</span></h2><div  class = 'S2'><span>The most direct way to load a model into The COBRA Toolbox is to use the </span><span style=' font-family: monospace;'>readCbModel</span><span> function. For example, to load a model from a MAT-file, you can simply use the filename (with or without file extension). </span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span >fileName = </span><span style="color: rgb(170, 4, 249);">'ecoli_core_model.mat'</span><span >;</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'><span style="white-space: normal"><span >model = readCbModel(fileName);</span></span></div></div></div><div  class = 'S8'><span>The </span><span style=' font-family: monospace;'>readCbModel </span><span>function has a second optional input that specifies the file type being loaded. In the above example the file type does not need to be specified since the input default is a 'Matlab' file type. To load file types other than a MAT-file, specificy the file type for input as: ‘SBML’, ‘SimPheny’, ‘SimPhenyPlus’, ‘SimPhenyText’, or 'Excel’. </span></div><div  class = 'S2'><span>You can also call the </span><span style=' font-family: monospace;'>readCbModel </span><span>function without a fileName to get a dialog box. This is provided when the Java feature is available. </span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">if </span><span >usejava(</span><span style="color: rgb(170, 4, 249);">'desktop'</span><span >) </span><span style="color: rgb(2, 128, 9);">% This line of code is to avoid execution of example in non gui-environments    </span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    model = readCbModel();</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><div  class = 'S2'><span>Once the model is loaded it can be used directly with The COBRA Toolbox functions. To view the data stored in the model use the following command.</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">if </span><span >usejava(</span><span style="color: rgb(170, 4, 249);">'desktop'</span><span >) </span><span style="color: rgb(2, 128, 9);">% This line of code is to avoid execution of example in non gui-environments    </span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    open </span><span style="color: rgb(170, 4, 249);">model</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><h2  class = 'S5'><span>Anticipated results</span></h2><div  class = 'S2'><span>After reading the model you should have a struct called model in your workspace. This struct should look approximately like:</span></div><div  class = 'S12'><img class = "imageNode" src = "" width = "407" height = "332" alt = "" style = "vertical-align: baseline"></img></div><div  class = 'S2'><span>In general, the following fields should always be present: </span></div><ul  class = 'S3'><li  class = 'S4'><span>rxns, the identifiers of the reactions</span></li><li  class = 'S4'><span>mets, the identifiers of the metabolites</span></li><li  class = 'S4'><span>genes, the list of genes in your model (can be empty)</span></li><li  class = 'S4'><span>rules, the Gene-protein-reaction rules in a computer readable format present in your model.</span></li><li  class = 'S4'><span>S, the stoichiometric matrix</span></li><li  class = 'S4'><span>lb, the lower bounds of the reactions</span></li><li  class = 'S4'><span>ub, the upper bounds of the reactions</span></li><li  class = 'S4'><span>osense, the objective sense (by convention, -1 indicates maximisation, 1 minimisation)</span></li><li  class = 'S4'><span>b, Accumulation (positive) or depletion (negative) of the corresponding metabolites. 0 Indicates no concentration change. </span></li><li  class = 'S4'><span>csense, indicator whether the b vector is a lower bound ('G'), upper bound ('L'), or hard constraint 'E' for the metabolite.</span></li></ul><h2  class = 'S5'><span>Writing a model (timing: 1 second to a few minutes)</span></h2><div  class = 'S2'><span>To wr</span><span>ite files, use the </span><span style=' font-family: monospace;'>writeCbModel</span><span> function</span><span>.</span><span> A dialog box will appear, select or enter the filename and the file format. The output is then generated and saved to the directory indicated in the diaglog box. A summary of the fields present in the model will also appear in the command window. </span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">if </span><span >usejava(</span><span style="color: rgb(170, 4, 249);">'desktop'</span><span >) </span><span style="color: rgb(2, 128, 9);">% This line of code is to avoid execution of example in non gui-environments</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    writeCbModel(model)</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><div  class = 'S2'><span>The </span><span style=' font-family: monospace;'>writeCbModel </span><span>function has a second optional input that specifies the file type in which the model should be written and saved. In the above example the file type was not specified and so the default file type to be saved was as a MAT-file. To use the function to write a file types other than a MAT-file, specificy the file type for input as: ‘text’,’xls’, or ‘sbml’. </span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">if </span><span >usejava(</span><span style="color: rgb(170, 4, 249);">'desktop'</span><span >) </span><span style="color: rgb(2, 128, 9);">% This line of code is to avoid execution of example in non gui-environments</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    writeCbModel(model,</span><span style="color: rgb(170, 4, 249);">'text'</span><span >)</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S13'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div><div  class = 'S7'><div class="inlineElement eoOutputWrapper embeddedOutputsErrorElement" uid="DF352A5A" data-testid="output_1" data-width="428" data-height="58" data-hashorizontaloverflow="false" style="width: 458px; max-height: 261px; white-space: normal; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;"><div class="diagnosticMessage-wrapper diagnosticMessage-errorType" style="white-space: normal; font-style: normal; color: rgb(230, 0, 0); font-size: 12px;"><div class="diagnosticMessage-messagePart" style="white-space: normal; font-style: normal; color: rgb(230, 0, 0); font-size: 12px;">Undefined function or variable 'fileName'.</div><div class="diagnosticMessage-stackPart" style="white-space: normal; font-style: normal; color: rgb(230, 0, 0); font-size: 12px;"><br style="white-space: normal; font-style: normal; color: rgb(230, 0, 0); font-size: 12px;">Error in writeCbModel (line 143)<br style="white-space: normal; font-style: normal; color: rgb(230, 0, 0); font-size: 12px;">if isempty(fileName)</div></div></div></div></div></div><div  class = 'S2'><span>It is also possible</span><span> to sp</span><span>e</span><span>cify the f</span><span>i</span><span>le name explicitly using the 'fileName' parameter. The following example writes a model directly to the file name 'Acidaminococcus.xml'.</span></div><div  class = 'S2'><span>The toolbox automatically determines the output from the file extension provided. '.xml'  indicates an SBML file, '.xls/.xlsx' an excel output and '.mat' a matlab save file. The return value of writeCbModel is either the input model struct, or the sbmlstruct used for TranslateSBML.</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">if </span><span >usejava(</span><span style="color: rgb(170, 4, 249);">'desktop'</span><span >) </span><span style="color: rgb(2, 128, 9);">% This line of code is to avoid execution of example in non gui-environments</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    writeCbModel(model, </span><span style="color: rgb(170, 4, 249);">'fileName'</span><span >, </span><span style="color: rgb(170, 4, 249);">'Acidaminococcus.xml'</span><span >)</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'></div></div></div><div  class = 'S8'><span>If a non standard file extension is required, you have to specify the format of the output using the 'format' parameter. the available options are: 'sbml', 'xls', 'mat', 'txt'</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">if </span><span >usejava(</span><span style="color: rgb(170, 4, 249);">'desktop'</span><span >) </span><span style="color: rgb(2, 128, 9);">% This line of code is to avoid execution of example in non gui-environments</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    writeCbModel(model, </span><span style="color: rgb(170, 4, 249);">'fileName'</span><span >, </span><span style="color: rgb(170, 4, 249);">'Acidaminococcus.sbml'</span><span >,</span><span style="color: rgb(170, 4, 249);">'format'</span><span >,</span><span style="color: rgb(170, 4, 249);">'sbml'</span><span >)</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><h2  class = 'S5'><span>Anticipated Results</span></h2><div  class = 'S2'><span>A file with the given filename containing the model in the specified format.</span></div><h2  class = 'S5'><span>CLEAN UP</span></h2><div  class = 'S2'><span>Clean up of materials used in the tutorial.  </span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S9'><span style="white-space: normal"><span >currentDir = pwd;</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >cd(fileparts(which(</span><span style="color: rgb(170, 4, 249);">'tutorial_IO.mlx'</span><span >)));</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span style="color: rgb(2, 128, 9);">% Delete the files used in this tutorial (if they are present).</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">try</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    delete(</span><span style="color: rgb(170, 4, 249);">'ecoli_core_model.mat'</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    delete(</span><span style="color: rgb(170, 4, 249);">'Acidaminococcus.xml'</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span >    delete(</span><span style="color: rgb(170, 4, 249);">'Acidaminococcus.sbml'</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: normal"><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S11'><span style="white-space: normal"><span >cd(currentDir)</span></span></div></div></div><h2  class = 'S5'><span>REFERENCES</span></h2><div  class = 'S2'><span>[1] Reconstruction and Use of Microbial Metabolic Networks: the Core Escherichia coli Metabolic Model as an Educational Guide by Orth, Fleming, and Palsson (2010)</span></div>
<br>
<!-- 
##### SOURCE BEGIN #####
%% Input and output of reconstructions and models 
%% Author(s): Thomas Pfau, LCSB, University of Luxembourg.
%% Reviewers: Catherine Clancy, LCSB, University of Luxembourg.
%% Francisco J. Planes, Department of Biomedical Engineering and Sciences, Tecnun, University of Navarra.
%% INTRODUCTION
% This tutorial aims at providing information on how to load models into The 
% COBRA Toolbox and export them to other formats.
%% Available input formats
% The COBRA Toolbox supports the use of models in multiple formats, including:
%% 
% * MAT-file format 
% * Systems Biology Markup Language (SBML) format 
% * SimPheny format
% * Excel format
%% 
% The most commonly used model format is a MAT-file (|.mat| ) format where by 
% a simple MATLAB |struct| contains one or more of the fields defined in The COBRA 
% Toolbox <https://opencobra.github.io/cobratoolbox/docs/COBRAModelFields.html 
% Documentation>. 
%% MAT-file format
% A model in a MAT-file format is required to follow the rules defined in The 
% COBRA Toolbox <https://opencobra.github.io/cobratoolbox/docs/ExcelModelFileDefinition.html 
% Documentation>. 
%% SBML format
% The COBRA Toolbox currently supports models formats of SBML Level 3 version 
% 1 (as defined <http://sbml.org/Documents/Specifications here>) and has legacy 
% support for older versions of SBML. It also supports the Level 3 Flux Balance 
% Constraints (FBC) package (both in version 1 and version 2). 
% 
% The COBRA Toolbox will use the provided SBML IDs as IDs for the respective 
% elements of the model structure, and use the name fields as names. It is assumed 
% (but not necessary), that metabolite IDs start with a "M_", reaction IDs start 
% with a "R_" , gene IDs start with a "G_", and compartment IDs start with a "C_". 
% This is due to the limitation on identifiers in SBML and those starting sequences 
% will be removed if they are consistently present in the model. 
% 
% Metabolite IDs of the MAT-file format use a metabolite identfier followed 
% by a compartment identifier in square brackets (e.g. ala_L[c]). Since brackets 
% are illegal characters for SBML IDs, The COBRA Toolbox assumes, for all non 
% boundary species, that a compartment identifier preceded by an underscore (e.g. 
% SBML ID: M_ala_L_c) is equivalent to the MAT-file compartment identifiers and 
% converted to a model as such.
% 
% The COBRA Toolbox has a legacy support for the NOTE Fields defined in <http://www.nature.com/nprot/journal/v6/n9/abs/nprot.2011.308.html 
% Schellenberger et al, Nature Protocols, 2011>, but it is suggested to instead 
% use annotations whenever possible. In general, if a fbc-package field and a 
% NOTES field is present, the fbc-package value will be used (e.g. CHARGE for 
% metabolites, or GENE_ASSOCIATION for reactions). The same applies to annotations, 
% i.e. if there is an annotation for an EC number, the Notes field EC Number will 
% be ignored. However, the charge field in SBML Level 2 will be overwritten by 
% the Notes field definitions.
%% *SimPheny format*
% SimPheny models provided in 3 or 4 files (4 if GPR rules are provided). The 
% model identifiers will be used as presented in the SimPheny files.
%% Excel format
% A model in a excel file formats are accepted by The COBRA Toolbox if the file 
% adheres to the specifications listed in The COBRA Toolbox <https://opencobra.github.io/cobratoolbox/docs/ExcelModelFileDefinition.html 
% Documentation>. 
%% Available output formats
% The COBRA Toolbox also allows storage in multiple file types as detailed below.
%% MAT-files formats
% The MAT-file (|.mat| ) format is most commonly used. The MAT-file format make 
% up is a simple MATLAB |struct| containing one or more of the fields defined 
% in The COBRA Toolbox <https://opencobra.github.io/cobratoolbox/docs/COBRAModelFields.html 
% Documentation>. It has the advantage of lossless data storage even for model 
% specific fields not supported by The COBRA Toolbox.
%% SBML format 
% SBML is a commonly used format to store biological models. The COBRA Toolbox 
% allows the generation of models using SBML Level 3 Version 1 and uses the FBC-package 
% extension to encode constraint based properties. This is the format that is 
% recommended for publication, as it can be used by many different tools and allows 
% the best use of the model.
%% Excel format
% Historically, models were often exchanged using Excel files, and this is still 
% in use today. Some users prefer to have an overview of a model using Excel. 
% The COBRA Toolbox offers an Excel export of the format described in The COBRA 
% Toolbox <https://opencobra.github.io/cobratoolbox/docs/ExcelModelFileDefinition.html 
% Documentation>.
%% Text Format
% Finally, The COBRA Toolbox offers a simple textual export, which is essentially 
% a tab separated file containing the reactions with their reaction formulas along 
% with the associated GPRs, but no further information. This format only uses 
% the required fields and will ignore any optional fields.
%% EQUIPMENT SETUP
%% *Initialize the COBRA Toolbox.*
% Initialize The Cobra Toolbox using the |initCobraToolbox| function.

initCobraToolbox(false) % false, as we don't want to update
%% 
% For this tutorial we will use a MAT-file formated model of the _E.coli core_ 
% model [1]. First we will load the model into the tutorial directory (cleaning 
% any old copies).

cd(fileparts(which('tutorial_IO.mlx')));

% Copy the file required for this tutorial (if they are not yet present).
try
    delete 'ecoli_core_model.mat';
    copyfile(which('ecoli_core_model.mat'), '.');
end
%% PROCEDURE
% The time that it takes to load a model depends on the file format, the complexity 
% of a model and the machine. The loading of a MAT-file, even of some large models, 
% can take only seconds, whereas large SBML files can take a few minutes to load. 
%% Reading a model (timing: 1 second to a few minutes)
% The most direct way to load a model into The COBRA Toolbox is to use the |readCbModel| 
% function. For example, to load a model from a MAT-file, you can simply use the 
% filename (with or without file extension). 

fileName = 'ecoli_core_model.mat';
model = readCbModel(fileName);
%% 
% The |readCbModel| function has a second optional input that specifies the 
% file type being loaded. In the above example the file type does not need to 
% be specified since the input default is a 'Matlab' file type. To load file types 
% other than a MAT-file, specificy the file type for input as: ‘SBML’, ‘SimPheny’, 
% ‘SimPhenyPlus’, ‘SimPhenyText’, or 'Excel’. 
%% 
% You can also call the |readCbModel| function without a fileName to get a dialog 
% box. This is provided when the Java feature is available. 

if usejava('desktop') % This line of code is to avoid execution of example in non gui-environments    
    model = readCbModel();
end
%% 
% Once the model is loaded it can be used directly with The COBRA Toolbox functions. 
% To view the data stored in the model use the following command.

if usejava('desktop') % This line of code is to avoid execution of example in non gui-environments    
    open model
end
%% Anticipated results
% After reading the model you should have a struct called model in your workspace. 
% This struct should look approximately like:
% 
% 
% 
% In general, the following fields should always be present: 
%% 
% * rxns, the identifiers of the reactions
% * mets, the identifiers of the metabolites
% * genes, the list of genes in your model (can be empty)
% * rules, the Gene-protein-reaction rules in a computer readable format present 
% in your model.
% * S, the stoichiometric matrix
% * lb, the lower bounds of the reactions
% * ub, the upper bounds of the reactions
% * osense, the objective sense (by convention, -1 indicates maximisation, 1 
% minimisation)
% * b, Accumulation (positive) or depletion (negative) of the corresponding 
% metabolites. 0 Indicates no concentration change. 
% * csense, indicator whether the b vector is a lower bound ('G'), upper bound 
% ('L'), or hard constraint 'E' for the metabolite.
%% Writing a model (timing: 1 second to a few minutes)
% To write files, use the |writeCbModel| function. A dialog box will appear, 
% select or enter the filename and the file format. The output is then generated 
% and saved to the directory indicated in the diaglog box. A summary of the fields 
% present in the model will also appear in the command window. 

if usejava('desktop') % This line of code is to avoid execution of example in non gui-environments
    writeCbModel(model)
end
%% 
% The |writeCbModel| function has a second optional input that specifies the 
% file type in which the model should be written and saved. In the above example 
% the file type was not specified and so the default file type to be saved was 
% as a MAT-file. To use the function to write a file types other than a MAT-file, 
% specificy the file type for input as: ‘text’,’xls’, or ‘sbml’. 

if usejava('desktop') % This line of code is to avoid execution of example in non gui-environments
    writeCbModel(model,'text')
end
%% 
% It is also possible to specify the file name explicitly using the 'fileName' 
% parameter. The following example writes a model directly to the file name 'Acidaminococcus.xml'.
% 
% The toolbox automatically determines the output from the file extension provided. 
% '.xml'  indicates an SBML file, '.xls/.xlsx' an excel output and '.mat' a matlab 
% save file. The return value of writeCbModel is either the input model struct, 
% or the sbmlstruct used for TranslateSBML.

if usejava('desktop') % This line of code is to avoid execution of example in non gui-environments
    writeCbModel(model, 'fileName', 'Acidaminococcus.xml')
end

%% 
% If a non standard file extension is required, you have to specify the format 
% of the output using the 'format' parameter. the available options are: 'sbml', 
% 'xls', 'mat', 'txt'

if usejava('desktop') % This line of code is to avoid execution of example in non gui-environments
    writeCbModel(model, 'fileName', 'Acidaminococcus.sbml','format','sbml')
end
%% Anticipated Results
% A file with the given filename containing the model in the specified format.
%% CLEAN UP
% Clean up of materials used in the tutorial.  

currentDir = pwd;
cd(fileparts(which('tutorial_IO.mlx')));

% Delete the files used in this tutorial (if they are present).
try
    delete('ecoli_core_model.mat');
    delete('Acidaminococcus.xml');
    delete('Acidaminococcus.sbml');
end
cd(currentDir)
%% REFERENCES
% [1] Reconstruction and Use of Microbial Metabolic Networks: the Core Escherichia 
% coli Metabolic Model as an Educational Guide by Orth, Fleming, and Palsson (2010)
##### SOURCE END #####
-->
</div></body></html>